package 反射.作业;

import cn.itcast.domain.Student;

import java.lang.reflect.Field;

public class 通过反射操作属性 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Student student = new Student();

        Class clazz1 = Student.class;

        Field name = clazz1.getDeclaredField("name");

        name.setAccessible(true);

        name.set(student,"张三");

        name.get(student);

        System.out.println(student);


        Class clazz2 = Student.class;

        Field age = clazz2.getDeclaredField("age");

        age.setAccessible(true);

        age.set(student,22);

        age.get(student);

        System.out.println(student);
    }
}
